<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./js/vue.js"></script>
</head>

<body>
    <div class="app">
        {{name}}

        <navbar @myevent="handleReceive">

        </navbar>
    </div>


</body>
<script>
    Vue.component("navbar", {
        template: `
        <div>
            <input type="text" v-model="iname">------>{{iname}}
            <button @click="handleClick">点我发送数据给父类</button>
        </div>
        `,
        data() {
            return { iname: '' }
        },
        methods: {
            handleClick() {
                this.$emit('myevent', this.iname)
            }
        }
    })
    new Vue({
        el: '.app',
        data: {
            name: ''
        },
        methods: {
            handleReceive(iname) {
                this.name = iname


            }

        }
    })
</script>

</html>